/**
 * Created by hps on 17-4-30.
 */
public class FirstLastList {
    private Link1 first;
    private Link1 last;

    public boolean isEmpty() {
        return first == null;
    }

    public void insertFirst(Link1 link1) {
        if (isEmpty())
            last = link1;
        link1.next = first;
        first = link1;
    }

    public void insertLast(Link1 link1) {
        if(isEmpty())
            first = link1;
        else
            last.next = link1;
        last = link1;
    }

    public long deleteFirst() {
        Link1 temp = first;
        if(first.next == null)
            last = null;
        first = first.next;
        return temp.dData;
    }

    public void  displayList() {
        System.out.print("List (first-->last): ");
        Link1 current = first;
        while (current != null) {
            current.displayLink();
            current = current.next;
        }
        System.out.println();
    }
}
